% This is the file that generates/simulates the optimal contract for given parameteer values
% The function optparam gives out the optimal alpha and gamma (as well as values for p*, p**,
% firm profit, the probability of expropriation and country utility), given an input of mu_h 
% (the cost of expropriation), non-oil GDP, oil-production and the value of delta (the efficiency
% loss when the country is in autarky.

clear
clc

global x0

% Set starting point for alpha and gamma

x0 =  [46.766,  0.5];


k  = 0;

% Now iterate through values of i 
for i = 0:0.005:0.1
    k = k+1;
    [z w]     = optparam(2,50,1,i);   % optparam(muh, nonoilgdp1, oilprod1, delta1)
    input(k)  = i;
    alpha(k)  = z(1);
    gamma(k)  = z(2);
    p1star(k) = z(3);
    p2star(k) = z(4);
    Profit(k) = z(5);
    ProbExp(k)= z(6);
    Util(k)   = w;
    
    % Update the next starting point
    x0  =  [z(1), z(2)];

end

% Output
[input;
 alpha;
 gamma;
 probexp;
 p1star;
 p2star;
 util;
 profit]

number_iter = number_iter + 0.1;